/*
 * @Description: 单位导航包裹组件
 * @Author: Rfan
 * @Date: 2022-02-10 13:40:29
 * @LastEditTime: 2022-09-08 14:33:50
 */

import { useSearchParams } from 'react-router-dom';
import { useFondContext } from '../contexts/FondContext';
import UnitsNav from '@/components/UnitsNav';
import { appState } from '@/store/mobx';

const UnitSidebar = () => {
  const { setSelectUnit } = useFondContext();
  const [searchParams] = useSearchParams();

  const defaultUnit: number =
    parseInt(searchParams.get('unitId'), 10) || (appState.unitId as number);

  const handleChange = (id: number, item: any) => {
    setSelectUnit(item);
  };

  return (
    <>
      <UnitsNav defaultValue={defaultUnit} onChange={handleChange} />
    </>
  );
};

export default UnitSidebar;
